//
//  NewsListTableViewCell.m
//  DaiShengInvest
//
//  Created by 张睿 on 2017/7/19.
//  Copyright © 2017年 davinci. All rights reserved.
//

#import "NewsListTableViewCell.h"

@interface NewsListTableViewCell ()

@property (nonatomic, strong)UIView * lineView;

@end

@implementation NewsListTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return self;
}



- (void)setupUI{
    
    self.backgroundColor = [UIColor clearColor];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
 
    
    self.titleLabel = [UILabel new];
    
    self.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:17 * SCREENH6];
    self.titleLabel.textColor = ColorWithRGB(0xffffff);
    self.titleLabel.textAlignment = NSTextAlignmentLeft;
    
    [self addSubview:self.titleLabel];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self).offset(15 * SCREENH6);
        make.top.mas_equalTo(self).offset(15 * SCREENH6);
    }];
    
    
    self.timeLabel = [UILabel new];
    
    self.timeLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12 * SCREENH6];
    self.timeLabel.textColor = ColorWithRGB(0xa8a8a8);
    self.timeLabel.textAlignment = NSTextAlignmentLeft;
    
    [self addSubview:self.timeLabel];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.titleLabel);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(5 * SCREENH6);
    }];
    
    
    self.detailLabel = [UILabel new];
    
    self.detailLabel.font = [UIFont fontWithName:@"PingFangSC-Light" size:15 * SCREENH6];
    self.detailLabel.textColor = ColorWithRGB(0xa9a9a9);
    self.detailLabel.textAlignment = NSTextAlignmentLeft;
    self.detailLabel.numberOfLines = 0;
    
    [self addSubview:self.detailLabel];
    
    [self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.timeLabel);
        make.trailing.mas_equalTo(self).offset(-15 * SCREENH6);
        make.top.mas_equalTo(self.timeLabel.mas_bottom).offset(10 * SCREENH6);
        make.bottom.mas_equalTo(self).offset(-10 * SCREENH6);
    }];
    
    
    self.lineView = [UIView new];
    
    self.lineView.backgroundColor = [UIColor whiteColor];
    self.lineView.alpha = 0.1;
    
    [self addSubview:self.lineView];
    
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.mas_equalTo(self);
        make.height.mas_equalTo(1 * SCREENH6);
    }];
}



- (void)setModel:(NewsListModel *)model{
    
    _model = model;
    
    
    NSString *string = model.modifyTime;
    NSTimeInterval second = string.longLongValue / 1000.0;
    
    // 时间戳 -> NSDate *
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:second];
//    NSLog(@"%@", date);
    
    self.timeLabel.text = [NSString stringWithFormat:@"%@",date];
    self.detailLabel.text = model.brief;
    self.titleLabel.text = model.title;
    self.ID = [NSString stringWithFormat:@"%@",model.ID];
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
